home *** CD-ROM | disk | FTP | other *** search
- Path: hecate.umd.edu!ram
- From: ram@mbisgi.umd.edu (Ram Samudrala)
- Newsgroups: comp.infosystems.www.misc,comp.lang.misc,comp.lang.perl.misc,comp.lang.c
- Subject: Perl vs.C (was Re: Unix or NT? Get a Mac!)
- Followup-To: comp.infosystems.www.misc,comp.lang.misc,comp.lang.perl.misc,comp.lang.c
- Date: 4 Jan 1996 13:19:06 GMT
- Organization: The Centre for Advanced Research in Biotechnology
- Message-ID: <4cgk4a$pje@hecate.umd.edu>
- Reply-To: me@ram.org
- NNTP-Posting-Host: iris3.carb.nist.gov
- X-Newsreader: TIN [version 1.2 PL0]
-
- I'm posting this on comp.lang.c, and removing c.i.w.authoring.cgi.
-
- Mark Woodruff (netcom.com@netcom.com) wrote:
-
- >In languages, look for a match between the problem and the language,
- >rather than an arbitrary or artificial grading unrelated to the
- >problem.
-
- My first statement was fairly specific: it was related to the
- complexity of the task. Specifically, I mentioned ACM-type problems
- (and stuff related to my own research). The claims made were along
- the lines that Perl is 10 times faster to code than C, and only about
- 2-3 times slower in execution (if I recall right). I dispute this
- claim for any application once it goes past a certain level.
-
- >What if your problem was to search a telephone directory and identify
- >anyone with Serbo-Croatian names based on the top most common
- >Serbo-Croatian name *forms*? You could code and run the Perl version
- >long before you'd even be finished with your first design in C/C++.
- >Ya gotta look at the big picture.
-
- It depends. If your "form" can be specified as a regular expression,
- you could do it in C with a few lines of code; I just whipped up an
- example of doing regular expressions in C---took me 10 minutes to,
- including reading the man page (which I essentially ripped off the
- code from---the macros are all borrowed from the page). This is
- highly specific to SGI machines, but there' a standard for regexp()
- which is simlpler, I believe. So if you're searching a directory with
- tens of thousands of lines, it's clear this native approach is a good
- way. Of course, you could simply use egrep, which would make it
- one-line thing.
-
- Note that I don't consider this very complex and it is probably true
- that Perl (or some tool like egrep) would do a better job and/or be
- faster to code. My comment was mainly stating that there's a limit at
- which Perl stops being useful.
-
- >And what if your problem was to search a *real* telephone directory?
- >You could probably hire college students to do it faster by hand than
- >you could code it and run it in any language.
-
- Search a real telephone directory for what? If it's a number (i.e.,
- given a #, match a name), and if stuff is sorted, then I believe that
- coding a binary search in both C and Perl would take about the same
- time (could be wrong, I'll admit---if I code something in Perl, it'll
- look a lot like my C programs). If it's a regular expression, I'd use
- egrep.
-
- --Ram
-
- -- regexp example in C --
-
- #include <stdio.h>
-
- #define INIT register char *sp = instring;
- #define GETC() (*sp++)
- #define PEEKC() (*sp)
- #define UNGETC(c) (--sp)
- #define RETURN(c) return;
- #define ERROR(c) regerr(c)
- #define ESIZE 20000
-
- #include <regexp.h>
-
- void main(int argc, char *argv[])
- {
- char expbuf[ESIZE], line[200];
-
- compile(argv[1], expbuf, &expbuf[ESIZE], '\0');
- while (gets(line))
- {
- if (step(line, expbuf))
- printf("match found in %s\n", line);
- }
- }
-
- int regerr(int c)
- {
- fprintf(stderr, "regerr(): an error has occured: %d!\n", c);
- exit(0);
- }
-
-
- me@ram.org || http://www.ram.org || http://www.twisted-helices.com/th
- Unfortunately people are not rebelling against Microsoft.
- They don't know any better. ---Steve Jobs
-